package com.android.qjpmc.application_module.home.viewModel;

import com.android.qjpmc.application_module.home.contract.HomePageContract;
import com.android.qjpmc.application_module.home.model.StationDataModel;
import com.android.qjpmc.bean.SiteStationBean;
import com.android.qjpmc.widget.manager.RxJavaHttpManager;
import com.android.qjpmc.widget.manager.retrofit.RetrofitJsonManager;
import com.android.qjpmc.widget.mvvm.factory.CreateModel;
import com.android.qjpmc.widget.retrofithelper.rxsubscriber.ProgressObserver;
import com.android.qjpmc.data_module.PwrDataModule;

import java.util.List;

@CreateModel(StationDataModel.class)
public class HomePageViewModel extends HomePageContract.ViewModel {

    //获取并生成站列表, List<SiteStationBean>, 并更新到界面上去
    @Override
    public void getStationList() {
        if (PwrDataModule.getInstance().IsStationDownLoad() == 1) {
            mView.returnSiteStationData(PwrDataModule.getInstance().GetStaionBeanList());
        }
        mModel.getStationList().subscribe(new ProgressObserver<List<SiteStationBean>>(false, this) {
                                              @Override
                                              public void _onNext(List<SiteStationBean> siteStationBeans) {
                                                  //更新到界面...
                                                  PwrDataModule.getInstance().CreateStationByBeanList(siteStationBeans);
                                                  PwrDataModule.getInstance().SetStationDownMark(1);
                                                  mView.returnSiteStationData(siteStationBeans);
                                              }

                                              @Override
                                              public void _onError(String errorMessage, int errorCode) {
                                                  super._onError(errorMessage, errorCode);
                                              }
                                          }
        );
    }
}
/*
    public void getStationList() {
        if (PwrDataModule.getInstance().IsStationDownLoad() == 1)
        {
            mView.returnSiteStationData(PwrDataModule.getInstance().GetStaionBeanList() );
        }

        mModel.getStationList()
                .subscribe(new ProgressObserver<List<SiteStationBean>>(false,this) {
                    @Override
                    public void _onNext(List<SiteStationBean> siteStationBeans) {
                        PwrDataModule.getInstance().CreateStationByBeanList(siteStationBeans);
                        PwrDataModule.getInstance().SetStationDownMark(1);
                        mView.returnSiteStationData(siteStationBeans);
                    }

                    @Override
                    public void _onError(String errorMessage, int errorCode) {
                        super._onError(errorMessage, errorCode);
                    }
                });
    }
* */